﻿using System;
using System.Web.Services;
using phudieuhungthinh.BL;
using phudieuhungthinh.BL.Model;

namespace phudieuhungthinh.Admin
{
    public partial class CategoryItem : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        [WebMethod(EnableSession = true)]
        public static object GetCategory(int id)
        {
            try
            {
                var categoryImpl = new CategoryImpl();
                CategoryModel categoryModel = categoryImpl.GetCategoryModel(id);
                return categoryModel;
            }
            catch
            {
                return null;
            }
        }

        [WebMethod(EnableSession = true)]
        public static bool SaveCategory(CategoryModel categoryModel)
        {
            try
            {
                var categoryImpl = new CategoryImpl();
                if (categoryModel.ID != 0)
                {
                    categoryImpl.UpdateCategory(categoryModel);
                }
                else
                {
                    categoryModel.UniqueID = Guid.NewGuid();
                    categoryModel.Orders = 0;
                    categoryModel.IsActived = true;
                    categoryImpl.AddCategory(categoryModel);
                }
                return true;
            }
            catch(Exception)
            {
                return false;
            }
        }
    }
}